//  引入文件
import router from './router'
import store from './store'
// 权限控制
// 白名单
const WhiteList = ['/login', '/404']
// 路由的前置首位
router.beforeEach((to, from, next) => {
  // 从vuex中取token判断
  const token = store.state.user.token
  if (token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (WhiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
